package com.pine.dbant.core.web;

import com.pine.dbant.common.plugin.PluginMeta;
import com.pine.dbant.common.plugin.PluginType;
import com.pine.dbant.core.service.PluginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author xiaoyuan
 * @create 2022/11/30 9:57
 **/
@Api(tags = "插件服务")
@RestController
@RequestMapping("/plugin")
public class PluginController extends BaseHandler {

    @Autowired
    private PluginService pluginService;

    /**
     * 获取某个插件信息
     *
     * @param name
     * @return
     */
    @ApiOperation("获取插件信息")
    @GetMapping("/getPluginMeta")
    public PluginMeta getPluginMeta(@NotBlank(message = "插件名称不能为空") String name) {
        return pluginService.getPluginMeta(name);
    }

    /**
     * 获取某个类型的插件集合
     *
     * @param pluginType
     * @return
     */
    @ApiOperation("获取某个类型的插件集合")
    @GetMapping("/getPlugins")
    public List<PluginMeta> getPlugins(PluginType pluginType) {
        return pluginService.getPlugins(pluginType==null?PluginType.DATABASE:pluginType);
    }

}
